
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <pthread.h>

#include "rtspservice.h"
#include "rtputils.h"
#include "ringfifo.h"
#include "rtsp_server.h"

extern int g_s32Quit ;

void * rtsp_cycle_run(void *pArgs)
{
	struct timespec ts = { 2, 0 };
	int s32MainFd = *(int *)pArgs;
	while (!g_s32Quit)
	{
		nanosleep(&ts, NULL);
		EventLoop(s32MainFd);
	}
}

int rtsp_init(void)
{
	pthread_t tid1;
	int s32MainFd,temp;
	
	pthread_t id;
	ringmalloc(400*1024);
	printf("[rtsp] RTSP server START\n");
	PrefsInit();
	printf("[rtsp] listen for client connecting...\n");
	signal(SIGINT, IntHandl);
	s32MainFd = tcp_listen(SERVER_RTSP_PORT_DEFAULT);
	if (ScheduleInit() == ERR_FATAL)
	{
		fprintf(stderr,"[rtsp] Fatal: Can't start scheduler %s, %i \nServer is aborting.\n", __FILE__, __LINE__);
		return 0;
	}
	RTP_port_pool_init(RTP_DEFAULT_PORT);
	pthread_create(&tid1, 0, rtsp_cycle_run, &s32MainFd);  //按键(uart)线程函数
	return 0;
}

